﻿/**
 * Form used for creating and editing of Tracings
 */
Ext.define('Sisconsolid.view.tracing.edit.Form', {
    extend: 'Ext.form.Panel',
    alias: 'widget.tracing.edit.form',
    requires: [
        'Ext.form.FieldSet',
		'Ext.form.FieldContainer',
		'Ext.form.field.Date',
        'Ext.form.field.Text',
		'Ext.form.field.Display',
		'Sisconsolid.ux.form.field.RemoteComboBox',
		'Sisconsolid.store.util.CellList',
		'Ext.form.RadioGroup',
		'Ext.form.field.Radio'
    ],	
    initComponent: function() {
        var me = this;
        Ext.applyIf(me, {
		    layout: {                        
				type: 'vbox',
				align: 'center'
     		},
		    bodyPadding: 10,
			fieldDefaults: {
				labelAlign: 'right',
				labelWidth: 150,
				allowBlank: false
			},
			items: [
                {
                    xtype: 'fieldset',
					title: translations.tracing,
					items: [						
						{
							xtype: 'fieldcontainer',
							layout: {
								type: 'vbox',
								align: 'center'
							},
							items: [
								{
									xtype: 'displayfield',
									name: 'tracingType',
									fieldCls: 'titletext'
								}
							]
						},
						{
							xtype: 'datefield',
							name: 'dateAccomplished',
							fieldLabel: translations.dateAccomplished,
							submitFormat: 'Y-m-d',
							maxValue: new Date(),
							width: 260
						},
						{
							xtype: 'timefield',
							name: 'timeAccomplished',
							fieldLabel: translations.timeAccomplished,
							format:'H:i',
							width: 225
						},
						{
							xtype: 'textarea',
							name: 'need',
							fieldLabel: translations.need,
							width: 420
						},
						{
							xtype: 'textarea',
							name: 'result',
							fieldLabel: translations.result,
							width: 420
						},
						{
							xtype: 'ux.form.field.remotecombobox',
							name: 'idCell',
							fieldLabel: translations.cell,
							store: {
								type: 'util.cellList'
							},
							valueField: 'key',									
							displayField: 'value',
							editable: false,
							forceSelection: true,
							width: 320
						},
						{								
							xtype: 'radiogroup',									
							fieldLabel: translations.attendedCell,
							name: 'attendedCell',
							setValue : function(myValue){                        
								var me = this;
								me.batchChanges(function() {
									me.eachBox(function(cb) {
									   cb.setValue(myValue == cb.inputValue);
									});
								});
							},
							items: [
								{
								    inputValue: true,
									boxLabel: translations.yes,
									name: 'attendedCell'
								}, {
									inputValue: false,
									boxLabel: translations.no,
									name: 'attendedCell'
								}
							],							
							listeners: {
								change: function (field, newValue, oldValue) {
									if (newValue.attendedCell == true) {
										Ext.ComponentQuery.query('[name=idCell]')[0].show();
									} else {
										Ext.ComponentQuery.query('[name=idCell]')[0].hide();
									}
								}
							},
		
							width: 250
						},
						{								
							xtype: 'radiogroup',									
							fieldLabel: translations.attendedService,
							name: 'attendedService',
							setValue : function(myValue){                        
								var me = this;
								me.batchChanges(function() {
									me.eachBox(function(cb) {
									   cb.setValue(myValue == cb.inputValue);
									});
								});
							},
							items: [
								{
								    inputValue: true,
									boxLabel: translations.yes,
									name: 'attendedService'
								}, {
									inputValue: false,
									boxLabel: translations.no,
									name: 'attendedService'
								}
							],
							width: 250
						}
					]
				}
            ]
        });
        me.callParent( arguments );
    }
});